{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/technological/css/style.css">
    <link rel="stylesheet" href="../../static/public_file/css/DepartmentSelection.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .add_background {
            background: #A9A9A9;
        }

        .input-style {
            display: inline-block;
            width: 100%;
            height: 35px;
            font-size: 14px;
            border: none;
            background: white;
        }

        tr td {
            padding-right: 5px;
            outline: none;
            height: 40px;
        }

        th {
            text-align: center;
        }

        .search {
            width: 300px;
            display: flex;
            margin: 10px 0;
            margin-right: 1%;
            /*border: 1px solid red;*/
        }

        .search input {
            vertical-align: middle;
            float: left;
        / / 左浮动 flex: 4;
            height: 30px;
            width: 230px;
            outline: none;
            border: 1px solid #0070c1;
            box-sizing: border-box;
        / / 盒子模型，怪异IE盒子模型，width = content + border * 2 + padding * 2 padding-left: 10 px;
            border-bottom-left-radius: 3px;
            border-top-left-radius: 3px;
        }

        .search button {
            float: right;
            flex: 1;
            height: 30px;
            width: 70px;
            line-height: 30px;
            background-color: #0070c1;
            color: white;
            border-style: none;
            outline: none;
            border-bottom-right-radius: 3px;
            border-top-right-radius: 3px;
        }

        .search button i {
            font-style: normal;
        }

        .search button:hover {
            font-size: 16px;
        }

        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }

        #addForm {
            width: 800px;
            height: 620px;
            background: #F5F5F5;
            position: absolute;
            border: #dfdfdf solid 1px;
            margin: auto;
            border-radius: 3px;
            top: 50%;
            left: 50%;
            /* 实现鼠标拖拽使用css3效果 */
            transform: translate(-50%, -50%);
            z-index: 10100;
            font-size: 0;
        }
        .shade {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(36, 36, 36, 0.5);
            display: none;z-index: 10000;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="business_contract_list_view" style="color: #0b0b0b;">经济合同会签</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 100%;height: 90%;display: inline-block;vertical-align: center;margin-top: 1.5%;">
                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;">
                        <tr>
                            <td colspan="4" style="width: 100%;height: 40px;padding-left: 0.5%;line-height: 40px;border: #cfcfcf solid 1px;text-align: center;">
                                <h3 id="form_name" style="letter-spacing: 8px;">经济合同会签流程</h3>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" style="width: 100%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #dfdfdf;border-left: #cfcfcf solid 0.5px;border-right: #cfcfcf solid 0.5px;">
                                基本信息
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                申请人
                            </td>
                            <td id="applicat"
                                style="width: 35%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ obj.apply_user.real_name }}</td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                填表时间
                            </td>
                            <td id="date"
                                style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;">{{ obj.create_time | date:"Y-m-d H:i" }}
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                立&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项&nbsp;&nbsp;&nbsp;&nbsp;科&nbsp;&nbsp;&nbsp;&nbsp;室
                            </td>
                            <td id="department" colspan="3"
                                style="width: 85%;border: #cfcfcf solid 0.5px;padding-left: 1%;line-height: 35px;">{{ obj.company.name }}</td>
                        </tr>
                    </table>
                </div>
                <div style="width: 95%;margin-left: 2.5%;;">
                    <table style="width: 100%;">
                        <tr>
                            <td colspan="4" style="width: 100%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #dfdfdf;border-left: #cfcfcf solid 0.5px;border-right: #cfcfcf solid 0.5px;">
                                申请详情
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;印&nbsp;&nbsp;&nbsp;&nbsp;份&nbsp;&nbsp;&nbsp;&nbsp;数
                            </td>
                            <td id="Printing" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;" contenteditable="{{ is_edit }}">{{ obj.Printing }}
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                物资需求科室
                            </td>
                            <td id="product_company" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;" onclick="show_office_model()" name="{{ xuqiu_id_str }}">{{ xuqiu_dep_str }}
                            </td>

                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                合&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;同&nbsp;&nbsp;&nbsp;&nbsp;名&nbsp;&nbsp;&nbsp;&nbsp;称
                            </td>
                            <td id="contract_name"
                                style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;"
                                contenteditable="{{ is_edit }}">{{ obj.contract_name }}
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;letter-spacing: 8px;">
                                合同编号
                            </td>
                            <td id="contract_number"
                                style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;"
                                contenteditable="{{ is_edit }}">{{ obj.contract_number }}
                            </td>

                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;letter-spacing: 1.1px;">
                                合&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;同&nbsp;&nbsp;&nbsp;&nbsp;类&nbsp;&nbsp;&nbsp;&nbsp;型
                            </td>
                            <td id="documentation" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;">
                                <select style="width: 100%;height: 95%;border: none;outline: none;" onchange="choose_contract()" name="" id="contract_type">
                                    <option value="0" {% if obj.contract_type == '0' %} selected {% endif %}>请选择合同类型</option>
                                    <option value="1" {% if obj.contract_type == '1' %} selected {% endif %}>服务类</option>
                                    <option value="2" {% if obj.contract_type == '2' %} selected {% endif %}>货物类</option>
                                    <option value="3" {% if obj.contract_type == '3' %} selected {% endif %}>工程类</option>
                                    <option value="4" {% if obj.contract_type == '4' %} selected {% endif %}>其它类</option>
                                </select>
                            </td>

                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;letter-spacing: 8px;">
                                对方单位
                            </td>
                            <td id="other_units"
                                style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;"
                                contenteditable="{{ is_edit }}">{{ obj.other_units }}
                            </td>
                        </tr>
                        <tr id="contract_date" style="margin-left: 1%;{% if obj.contract_type == '0' or obj.contract_type == '2' %} display: none; {% endif %}">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.8px;border-bottom: none;">
                                合&nbsp;&nbsp;同&nbsp;&nbsp;生&nbsp;&nbsp;效&nbsp;&nbsp;日
                            </td>
                            <td id="contract_effect" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;cursor: pointer;">{{ obj.contract_effect }}</td>

                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 4px;border-bottom: none;">
                                合同截止日
                            </td>
                            <td id="contract_off" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;cursor: pointer;">{{ obj.contract_off }}</td>
                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                合&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;同&nbsp;&nbsp;&nbsp;&nbsp;金&nbsp;&nbsp;&nbsp;&nbsp;额
                            </td>
                            <td id="contract_amount"
                                style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;"
                                contenteditable="{{ is_edit }}">{{ obj.contract_amount }}

                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 8px;">
                                经费来源
                            </td>
                            <td id="source"
                                style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;"
                                contenteditable="{{ is_edit }}">{{ obj.source }}

                            </td>

                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;letter-spacing: 2.5px;">
                                是否大于20万元
                            </td>
                            <td id="greater_than" colspan="3" style="width: 85%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;">
                                <input type="radio" name="greater" value="1" checked> 是
                                <input type="radio" name="greater" value="0" style="margin-left: 10px;"> 否
                            </td>
                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;">
                                合同内容主要条款
                            </td>
                            <td id="content"
                                style="width: 85%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;"
                                contenteditable="{{ is_edit }}">{{ obj.content }}</td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;">
                                备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注
                            </td>
                            <td id="beizhu" style="width: 85%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;" contenteditable="true">{{ obj.notes }}</td>
                        </tr>
                    </table>

                </div>
                <div style="width: 95%;margin-left: 2.5%; {% if is_edit == 'false' %}display: none{% endif %}">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        上传附件
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main">
                        {% for record in file_list %}
                            <tr>
                                <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">{{ forloop.counter }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_name }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_size }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.upload_time }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.uploader }}</td>
                                <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    <a target='_blank' href="{{ record.file_path }}">查看</a> | <a style="color: red;"
                                                                                                 href='#'
                                                                                                 onclick='RemoveTr(this, "party_main", {{ record.id }})'>删除</a>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>

                    </table>
                </div>
            </div>

        </div>
    </div>

    <div id="selection-office" class="office-shade">
        <div id="office-model">
            <!-- 标题 -->
            <div id="office-title">
                <h5 style="line-height: 40px;width: 15%;margin-left: 1%;display: inline-block;font-size: 14px;">选择科室</h5>
                <span onclick="close_office_models()" style="float: right;line-height: 50px;padding-right: 2%;cursor: pointer;"><i class="iconfont icon-quchu"></i></span>
            </div>
            <hr>
            <div style="width: 55%;height: 350px;vertical-align: top;left: 0;display: inline-block;border-right: #cfcfcf solid 1px;">
                <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                    <input id="search_data1" onkeydown="search_dep()" class="search-input" type="text" placeholder="搜索" autocomplete="off">
                </div>
                <div id="processed" style="width: 100%;height: 300px;overflow: auto;">
                    {% for company in company_list %}
                        <div style="width: 100%;height: 30px;line-height: 30px;font-size: 14px;color: #0b0b0b;">
                            <input class="check_box1" id="{{ company.id }}" type="checkbox" onclick="check_dep_ff('{{ company.name }}', '{{ company.id }}', false)"> {{ company.name }}
                        </div>
                    {% endfor %}
                </div>
            </div>

            <div style="width: 43%;height: 360px;vertical-align: top;left: 0;display: inline-block;">
                <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;font-size: 14px;">
                    已选择科室
                </div>
                <div id="processed_prople" style="width: 100%;height: 265px;overflow: auto;padding-left: 2%;">

                </div>
                <div style="width: 100%;height: 40px;text-align: center;">
                    <button onclick="summit_val()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #1E90FF solid 1px;background: #1E90FF;color: white;width: 80px;letter-spacing: 4px;font-size: 14px;">
                        提交
                    </button>
                    <button onclick="close_office_models()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #cfcfcf solid 1px;width: 80px;letter-spacing: 4px;margin-left: 15px;font-size: 14px;">
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->
    <script type="text/javascript" src="../../static/public_file/js/DepartmentSelection.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";

        };

        $('input:radio').click(function(){
            var $radio = $(this);
            if ($radio.data('checked')){
              $radio.prop('checked', false);
              $radio.data('checked', false);
            } else {
              $radio.prop('checked', true);
              $radio.data('checked', true);
            }
        });

        lay('#version').html('-v' + laydate.v);
        //执行一个laydate实例
        laydate.render({
            elem: '#contract_effect', //指定元素
            type: 'date',
            format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#contract_off', //指定元素
            type: 'date',
            format: 'yyyy-MM-dd'
        });

        function close_models1() {
            document.getElementById("new_models1").style.display = "none";
        }

        function show_model() {
            document.getElementById("new_models1").style.display = "table-row";
        }

        function summit_val() {
            var processed_prople = document.getElementsByClassName("selected-department");
            if (processed_prople.length === 0){
                alert("请选择拟稿科室！");
                return false
             }
            var dep_list=[];var product_company_list=[];
            for (var i=0; i<processed_prople.length; i++) {
                dep_list.push(processed_prople[i].innerText.split("(")[0])
                product_company_list.push(processed_prople[i].innerText.split("(")[1].replace(")", ''))
            }
            document.getElementById("product_company").innerText=dep_list.join();
            document.getElementById("product_company").setAttribute("name", product_company_list.join())
            close_office_models()
        }


        function search_dep() {
            var company_list = {{ company_list | safe }};
            var search_keyword = document.getElementById("search_data1").value;
            var processed = document.getElementById("processed");
            processed.innerHTML = "";
            for (var h=0; h<company_list.length; h++){
                if (company_list[h]["name"].indexOf(search_keyword) !== -1){
                    console.log(company_list[h]["name"])
                    var div_tag = document.createElement("div");div_tag.className="div_clase";
                    div_tag.innerHTML = '<input class="check_box1" id="'+company_list[h]["id"]+'" type="checkbox" onclick="check_dep_ff(\''+company_list[h]["name"]+'\', \''+company_list[h]["id"]+'\', false)"> '+ company_list[h]["name"];
                    processed.appendChild(div_tag)
                }
            }
        }

        const uuid = '{{ obj.fj_number }}'

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'jjht')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");
                    var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function commit_data() {
            var administrative_table = document.getElementById('party_main');
            if (!administrative_table.children.length) {
                alert("请上传附件！");
                return false
            }
            var product_company = document.getElementById('product_company').innerText;
            if (!product_company) {
                alert("请选择物资需求科室！");
                return false
            }
            var leader_list = document.getElementsByClassName("leader_check");
            var leader_check = '';
            for (var i=0; i<leader_list.length; i++) {
                if (leader_list[i].checked) {
                    leader_check = leader_list[i].value;
                }
            }
            var product_company_id = $("#product_company").attr("name")
            var contract_name = document.getElementById('contract_name').innerText;
            var contract_number = document.getElementById('contract_number').innerText;
            var documentation = document.getElementById('documentation').innerText;
            var other_units = document.getElementById('other_units').innerText;
            var contract_amount = document.getElementById('contract_amount').innerText;
            var source = document.getElementById('source').innerText;
            var content = document.getElementById('content').innerText;

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/business_contract_index_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("product_company_id=" + String(product_company_id) + "&id=" + String({{obj.id}}) + "&contract_name=" + String(contract_name) + "&contract_number=" + String(contract_number) + "&documentation=" + String(documentation) + "&other_units=" + String(other_units) + "&contract_amount=" + String(contract_amount) + "&source=" + String(source) + "&content=" + String(content)+"&leader_check="+String(leader_check));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("提交成功");
                            window.location = "/finance/business_contract_list_view";
                            document.getElementById("loading").style.display = "none";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };
        }

        function submit_data() {
            var administrative_table = document.getElementById('party_main');
            if (!administrative_table.children.length) {
                alert("请上传附件！");
                return false
            }
            var product_company = document.getElementById('product_company').innerText;
            if (!product_company) {
                alert("请选择物资需求科室！");
                return false
            }
            var contract_effect = document.getElementById("contract_effect").innerText;
            var contract_off = document.getElementById("contract_off").innerText;
            var contract_type = document.getElementById("contract_type").value;
            if (contract_type === "0"){
                alert('请选择合同类型！')
                return false
            }
            if (contract_type === "1") {
                if (!contract_effect) {
                    alert('合同生效日不能为空！')
                    return false
                }
                if (!contract_off) {
                    alert("合同截至日不能为空！");
                    return false
                }
            }
            var product_company_id = $("#product_company").attr("name")
            var contract_name = document.getElementById('contract_name').innerText;
            var contract_number = document.getElementById('contract_number').innerText;
            var documentation = document.getElementById('documentation').innerText;
            var other_units = document.getElementById('other_units').innerText;
            var contract_amount = document.getElementById('contract_amount').innerText;
            var source = document.getElementById('source').innerText;
            var content = document.getElementById('content').innerText;
            var Printing = document.getElementById('Printing').innerText;
            var beizhu = document.getElementById('beizhu').innerText;
            var greater = $("input[type=radio][name=greater]:checked").val();

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/business_contract_index_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("product_company_id=" + String(product_company_id) + "&id=" + String({{obj.id}}) + "&contract_name=" + String(contract_name) + "&contract_number=" + String(contract_number) + "&documentation=" + String(documentation) + "&other_units=" + String(other_units) + "&contract_amount=" + String(contract_amount) + "&source=" + String(source) + "&content=" + String(content) + "&uuid=" + String(uuid)+"&give_back=true"+"&Printing="+String(Printing)+"&greater="+String(greater)+"&contract_effect="+String(contract_effect)+"&contract_off="+String(contract_off)+"&contract_type="+contract_type+"&beizhu="+beizhu);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功");
                            window.location = "/finance/business_contract_list_view";
                            document.getElementById("loading").style.display = "none";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };
        }

        function save_data() {
            var product_company = document.getElementById('product_company').innerText;
            var product_company_id = $("#product_company").attr("name")
            var contract_name = document.getElementById('contract_name').innerText;
            var contract_number = document.getElementById('contract_number').innerText;
            var documentation = document.getElementById('documentation').innerText;
            var other_units = document.getElementById('other_units').innerText;
            var contract_amount = document.getElementById('contract_amount').innerText;
            var source = document.getElementById('source').innerText;
            var content = document.getElementById('content').innerText;
            var contract_effect = document.getElementById("contract_effect").innerText;
            var contract_off = document.getElementById("contract_off").innerText;
            var contract_type = document.getElementById("contract_type").value;
            var beizhu = document.getElementById("beizhu").innerText;
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/business_contract_draft_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("product_company_id=" + String(product_company_id) + "&contract_name=" + String(contract_name) + "&contract_number=" + String(contract_number) + "&documentation=" + String(documentation) + "&other_units=" + String(other_units) + "&contract_amount=" + String(contract_amount) + "&source=" + String(source) + "&content=" + String(content) + "&uuid=" + String(uuid) + "&id=" + String({{obj.id}})+"&contract_effect="+String(contract_effect)+"&contract_off="+String(contract_off)+"&contract_type="+contract_type+"&beizhu="+beizhu);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("提交成功");
                            window.location = "/finance/business_contract_list_view";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };

        }

        let title = document.querySelector("#title");
        let addForm = document.querySelector("#new_models");

        title.addEventListener("mousedown", function (e) {
            let x = e.pageX - addForm.offsetLeft;
            let y = e.pageY - addForm.offsetTop;

            document.addEventListener("mousemove", move);
            function move(e) {
                addForm.style.left = e.pageX - x + 'px';
                addForm.style.top = e.pageY - y + 'px';
            }

            document.addEventListener("mouseup", function (e) {
                document.removeEventListener("mousemove", move);
            })
        });

        function choose_contract() {
            var contract_type = document.getElementById("contract_type").value;
            if (contract_type === "1") {
                document.getElementById("contract_date").style.display = 'table-row';
            }else {
                document.getElementById("contract_date").style.display = 'none';
            }
        }
    </script>
{% endblock %}
